﻿using Dapper;
using ProTrack.Dto;
using ProTrack.IRepository.WareHouse;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Threading.Tasks;
using System.Transactions;

namespace ProTrack.Repository.WareHouse
{
    public class StockRepository : IStockRepository
    {
        public async Task<bool> AddSales(List<ItemStockDto> list, SqlConnection BaseConnection, IDbTransaction tran)
        {
            string sql = "update ItemStock set SalesCount=SalesCount+@Count where  ItemId=@ItemId and WareHouseId=@WareHouseId";
            var result = await BaseConnection.ExecuteAsync(sql, list, tran);

            return result > 0;
        }
        public async Task<bool> SubSales(List<ItemStockDto> list, SqlConnection BaseConnection, IDbTransaction tran)
        {
            string sql = "update ItemStock set SalesCount=SalesCount-@Count where  ItemId=@ItemId and WareHouseId=@WareHouseId";
            var result = await BaseConnection.ExecuteAsync(sql, list, tran);

            return result > 0;
        }

        public async Task<bool> AddStock(List<ItemStockDto> list, SqlConnection BaseConnection, IDbTransaction tran)
        {
            string sql = "update ItemStock set StockCount=StockCount+@Count where  ItemId=@ItemId and WareHouseId=@WareHouseId";
            var result = await BaseConnection.ExecuteAsync(sql, list, tran);

            return result > 0;
        }


        public async Task<bool> SubStock(List<ItemStockDto> list, SqlConnection BaseConnection, IDbTransaction tran)
        {
            string sql = "update ItemStock set StockCount=StockCount-@Count where  ItemId=@ItemId and WareHouseId=@WareHouseId";
            var result = await BaseConnection.ExecuteAsync(sql, list, tran);

            return result > 0;
        }
    }
}
